package com.algorithms.brownian;

public final class CollisionEvent implements Comparable<CollisionEvent> {

	protected final double time;// the collision time
	protected final Particle a, b;
	private final int countA, countB;

	public CollisionEvent(double t, Particle a, Particle b) {

		this.time = t;
		this.a = a;
		this.b = b;
		if (a != null) {
			this.countA = a.count();
		} else {
			this.countA = -1;
		}
		if (b != null) {
			this.countB = b.count();
		} else {
			this.countB = -1;
		}
	}

	@Override
	public int compareTo(CollisionEvent other) {
		if (this.time < other.time) {
			return -1;
		} else if (this.time > other.time) {
			return 1;
		} else
			return 0;
	}

	/**
	 * check the events between the event creation and now
	 * 
	 * @return true if it has, false otherwise
	 */
	public boolean isValid() {
		if (a != null && a.count() != countA) {
			return false;
		}
		if (b != null && b.count() != countB) {
			return false;
		}
		return true;
	}
}
